<?php
/*
 * Create by Sony K Wibisono,S.Si
 * e-mail : sony@sonywibisono.com.
 */
class NewsCategory {
    var $id;
    var $category_name;
    var $parent;
    function open($catid){
        global $db;
        $sql="select * frm _post_category where id=$id";
        $row=$db->fetch_row($sql);
        if (!empty($row)){
            $this->category_name=$category_name;
            $this->parent=$parent;
        }
    }
    function openAll(){
        global $db;
        $sql="select * frm _post_category order by id asc";
        $result=$db->query($sql);
        if (!empty($result)){
            return $db->fetch_array($result);
        }
    }
    function insert(){
        global $db;
        $sql="insert into _post_category values (null,'".
                $this->category_name."',".$this->parent.")";
        $db->query($sql);
        return mysql_insert_id();
    }
    function update(){
        global $db;
        $sql="update _post_category set category_name='".$this->category_name.
                "',parent=".$this->parent.
                "  where id=".$this->id;
        $db->query($sql);
    }
    function delete(){
        global $db;
        $sql="delete from _post_category where id=".$this->id;
        $db->query($sql);
    }
}
class NewsContents {
var $id;
var $title;
var $post_category;
var $excerpt;
var $contents;
var $hits;
var $user_creator;
var $date_create;


    function open(){
        global $db;
        $sql="select * from _post_contents where id=$id";
        $row=$db->fetch_row($sql);
        if (!empty($row)){
            extract($row);
            $this->title=$title;
            $this->post_category=$post_category;
            $this->excerpt=$excerpt;
            $this->contents=$contents;
            $this->hits=$hits;
            $this->user_creator=$user_creator;
            $this->date_create=$date_create;

        }
    }

    function openAll(){
        $sql="select * from _post_contents order by id asc";
        $result=$db->query($sql);
        return $db->fetch_array($result);
        
    }

    function insert(){
    global $db;
    $sql="insert into _post_contents values (null,'{$this->title}',
    '{$this->post_category}','{$this->excerpt}','{$this->contents}','{$this->hits}',
    '{$this->user_creator}',sysdate())";
    $db->query($sql);
    return mysql_insert_id();
    }
     
    function update(){
        global $db;
        $sql="update _post_contents set title='{$this->title}',
            post_category={$this->post_category},
            excerpt='{$this->excerpt}',
            contents='{$this->contents}' 
            where id=".$this->id;
        $db->query($sql);
    }

    function delete(){
        global $db;
        $sql="delete from _post_tags where post_id=".$this->id;
        $db->query($sql);
        $sql="delete from _post_comments where post_id=".$this->id;
        $db->query($sql);
        $sql="delete from _post_contents where id=".$this->id;
        $db->query($sql);
    }

}
?>
